package cn.golxen.rsms.commons.utils;


import com.fasterxml.jackson.annotation.JsonFormat;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class LocalDateTimeUtils {

    public static Date toDate(){
        LocalDateTime localDateTime = LocalDateTime.now();
        //获取系统默认时区
        ZoneId zoneId = ZoneId.systemDefault();
        //时区的日期和时间
        ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId);
        //获取时刻
        return Date.from(zonedDateTime.toInstant());
    }

    public static LocalDateTime getLocalDateTime(){
        //1.具有转换功能的对象
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        //2.要转换的对象
        //设置程序时区为东8区
//        System.setProperty("user.timezone","GMT +08");
        LocalDateTime time = LocalDateTime.now();


        //3.发动功能
        String localTime = df.format(time);
//        System.out.println(localTime);
        //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
        return LocalDateTime.parse(localTime,df);
    }


    public static String getWeChatPayTimeExpire(int hour){
        DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
        LocalDateTime time=LocalDateTime.now().plusHours(hour);
        String timeExpire=df.format(time);
        return timeExpire;

    }

    /**
     * 创建时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public LocalDateTime createTime;

}
